#include "stdafx.h"
#include "DnsRecordFactory.h"

using namespace Adaptive::Network::Dns;

DnsRecordFactory::DnsRecordFactory()
{
}

DnsAddressRecord^ DnsRecordFactory::CreateDnsAddressRecord(DNS_RECORD* originalRecord)
{
	DnsAddressRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_A) > 0)
		returnValue = gcnew DnsAddressRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsAddressRecord((DNS_RECORD*)NULL);
		returnValue->IP = nullptr;
	}
	return returnValue;
}

DnsATMAddressRecord^ DnsRecordFactory::CreateDnsATMAddressRecord(DNS_RECORD* originalRecord)
{
	DnsATMAddressRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_ATMA) > 0)
		returnValue = gcnew DnsATMAddressRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsATMAddressRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}


DnsIp6AddressRecord^ DnsRecordFactory::CreateDnsIp6AddressRecord( DNS_RECORD* originalRecord )
{
	DnsIp6AddressRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_AAAA) > 0)
		returnValue = gcnew DnsIp6AddressRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsIp6AddressRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsKeyRecord^ DnsRecordFactory::CreateDnsKeyRecord( DNS_RECORD* originalRecord )
{
	DnsKeyRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_KEY) > 0)
		returnValue = gcnew DnsKeyRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsKeyRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsMailExchangeRecord^ DnsRecordFactory::CreateDnsMailExchangeRecord( DNS_RECORD* originalRecord )
{
	DnsMailExchangeRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_MX) > 0)
		returnValue = gcnew DnsMailExchangeRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsMailExchangeRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsMailInformationRecord^ DnsRecordFactory::CreateDnsMailInformationRecord( DNS_RECORD* originalRecord )
{
	DnsMailInformationRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_MINFO) > 0)
		returnValue = gcnew DnsMailInformationRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsMailInformationRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsNextRecord^ DnsRecordFactory::CreateDnsNextRecord( DNS_RECORD* originalRecord )
{
	DnsNextRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_NXT) > 0)
		returnValue = gcnew DnsNextRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsNextRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsNullRecord^ DnsRecordFactory::CreateDnsNullRecord( DNS_RECORD* originalRecord )
{
	DnsNullRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_NULL) > 0)
		returnValue = gcnew DnsNullRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsNullRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsPointerRecord^ DnsRecordFactory::CreateDnsPointerRecord( DNS_RECORD* originalRecord )
{
	DnsPointerRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_PTR) > 0)
		returnValue = gcnew DnsPointerRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsPointerRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsServiceRecord^ DnsRecordFactory::CreateDnsServiceRecord( DNS_RECORD* originalRecord )
{
	DnsServiceRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_SRV) > 0)
		returnValue = gcnew DnsServiceRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsServiceRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsSignatureRecord^	 DnsRecordFactory::CreateDnsSignatureRecord( DNS_RECORD* originalRecord )
{
	DnsSignatureRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_SIG) > 0)
		returnValue = gcnew DnsSignatureRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsSignatureRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsStartOfAuthorityRecord^ DnsRecordFactory::CreateDnsStartOfAuthorityRecord( DNS_RECORD* originalRecord )
{
	DnsStartOfAuthorityRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_SOA) > 0)
		returnValue = gcnew DnsStartOfAuthorityRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsStartOfAuthorityRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsTextRecord^ DnsRecordFactory::CreateDnsTextRecord( DNS_RECORD* originalRecord )
{
	DnsTextRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_TEXT) > 0)
		returnValue = gcnew DnsTextRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsTextRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsTKeyRecord^ DnsRecordFactory::CreateDnsTKeyRecord( DNS_RECORD* originalRecord )
{
	DnsTKeyRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_TKEY) > 0)
		returnValue = gcnew DnsTKeyRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsTKeyRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsTSignatureRecord^ DnsRecordFactory::CreateDnsTSignatureRecord( DNS_RECORD* originalRecord )
{
	DnsTSignatureRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_TSIG) > 0)
		returnValue = gcnew DnsTSignatureRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsTSignatureRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsWellKnownServiceRecord^ DnsRecordFactory::CreateDnsWellKnownServiceRecord( DNS_RECORD* originalRecord )
{
	DnsWellKnownServiceRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_WKS) > 0)
		returnValue = gcnew DnsWellKnownServiceRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsWellKnownServiceRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsWINSRecord^ DnsRecordFactory::CreateDnsWINSRecord( DNS_RECORD* originalRecord )
{
	DnsWINSRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_WINS) > 0)
		returnValue = gcnew DnsWINSRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsWINSRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
DnsWINSReverseLookupRecord^ DnsRecordFactory::CreateDnsWINSReverseLookupRecord( DNS_RECORD* originalRecord )
{
	DnsWINSReverseLookupRecord^ returnValue = nullptr;

	//Create and initialize.
	if ((originalRecord->wType & DNS_TYPE_WINSR) > 0)
		returnValue = gcnew DnsWINSReverseLookupRecord(originalRecord);
	else
	{
		returnValue = gcnew DnsWINSReverseLookupRecord((DNS_RECORD*)NULL);
	}
	return returnValue;
}
